﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.Model;
using Gift.WebApp;

public partial class admin_system_role : BaseAdmin
{
   
    tbRole oRole;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BildForm();
        }
    }


    void BildForm()
    {
        if(!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            oRole = BaseFactory.theRole.GetModel(int.Parse(Request.QueryString["id"]));
            this.txtRoleName.Value = oRole.RoleName;
            this.txtRoleDescription.Value = oRole.Remark;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            oRole = BaseFactory.theRole.GetModel(int.Parse(Request.QueryString["id"]));
            oRole.RoleName = this.txtRoleName.Value.Trim();
            oRole.Remark = this.txtRoleDescription.Value;

            BaseFactory.theRole.Update(oRole);
        }
        else
        {
            oRole = new tbRole();
            oRole.RoleName = this.txtRoleName.Value.Trim();
            oRole.Remark = this.txtRoleDescription.Value;
            oRole.CompanyId = int.Parse(base.Administrator.CompanyId);
            BaseFactory.theRole.Add(oRole);
        }
        base.Response.Write("<script language='javascript'>;alert('保存成功！');window.location.href='roleList.aspx';</script>");

    }

}